package com.youzhi.backend.controller;


import com.youzhi.backend.dto.Result;
import com.youzhi.backend.request.UpdateLetterRequest;
import com.youzhi.backend.service.ILetterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.youzhi.backend.controller.BaseController;

import java.util.Map;

/**
 * <p>
 * 后台信件表 前端控制器
 * </p>
 *
 * @author xumeng
 * @since 2023-02-13
 */
@RestController
@Api(tags = "后台信件")
@RequestMapping("/letter")
public class LetterController extends BaseController {

    @Autowired
    private ILetterService letterService;


    @ApiOperation("获取当前登陆用户后台未读信件数")
    @RequiresUser
    @PostMapping("/unread/num")
    public Result<Map> getUnreadNum() {
        return Result.ok(letterService.getUnReadNum());
    }


    @ApiOperation("更新后台信件")
    @RequiresUser
    @PostMapping("/update")
    public Result updateLetter(@RequestBody UpdateLetterRequest request) {
        verifyIfBlank(request, UpdateLetterRequest.Fields.letterId,
                UpdateLetterRequest.Fields.isRead,
                UpdateLetterRequest.Fields.isDeleted);
        letterService.updateLetter(request);
        return Result.ok();
    }


}

